package logic

import (
	"context"
	"youngwind-first/rpcdemo/internal/svc"
	"youngwind-first/rpcdemo/model/gorm_model"
	"youngwind-first/rpcdemo/rpcdemo"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserInfoLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUserInfoLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserInfoLogic {
	return &UserInfoLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UserInfoLogic) UserInfo(in *rpcdemo.User) (*rpcdemo.User, error) {

	result := gorm_model.User{}
	err := l.svcCtx.DbEngin.Where("id = ?", in.Id).Find(&result).Error
	if err != nil {
		return nil, err
	}

	user := &rpcdemo.User{}
	user.Id = result.Id
	user.Name = result.Name
	user.Age = result.Age
	return user, nil
}
